//引入封装好的 service
import service from "../service";

// 声明一个基础接口变量
// let baseURL = 'http://192.168.122.124:8848/api/'; //124 nginx部署环境
// let baseURL = 'http://192.168.129.129:8848/api/'; //129测试环境
// let baseURL = 'http://192.168.129.129:8848/api/robot/'; //129测试环境
// let baseURL = ''; //124 后台部署环境
// let baseURL = 'http://localhost:8002/robot/'; //本地部署测试
// let baseURL = 'http://192.168.129.129:10103/airobot/'
// let baseURL = "/api/robot/"; //本地测试
let baseURL = process.env.NODE_ENV === "production" ? "/airobot/" : "/api/"; //本地测试其它环境

let token = "";
let userId = "";
let schoolId = "";
let version = "";
let role = "";
let identityCode = "";

//设置请求头（如果请求头统一的话可以在axios文件设置，则无须从这里传过去）
let header = {
  Accept: "application/json;charset=UTF-8",
  Authorization: "",
  device: "COMPUTER",
  userId: "",
};

export const setConfigByManage = (config) => {
  console.log("manage 传来的config = ", config);
  token = config.token;
  userId = config.userId;
  schoolId = config.schoolId;
  version = config.version;

  if (process.env.NODE_ENV === "production") {
    baseURL = config.addr; // 打包配置
  }

  header = {
    Accept: "application/json;charset=UTF-8",
    Authorization: token,
    device: "COMPUTER",
    userId: userId,
  };
};

export const api_getBaseUrl = async (token) => {
  const url = baseURL + "getBaseInfo";

  return service.get(url, null, { Authorization: token });
};

export const api_padiqsx = async () => {
  let data = {
    schoolId,
  };
  const url = baseURL + "padiqsx";
  return service.get(url, data, header);
};

export const getInstructs = async (data) => {
  const url = baseURL + "queryInstruct";
  return service.get(url, data, header);
};

export const removeInstructs = (data) => {
  const url = baseURL + "removeInstruct";
  return service.post(url, data, header);
};

export const postInstruct = (data) => {
  const url = baseURL + "addInstruct";
  return service.post(url, data, header);
};

export const openorclose = (data) => {
  const url = baseURL + "openorclose";
  return service.post(url, data, header);
};

/**
 * 新增指令的备注
 * @param {*} data
 * @returns
 */
export const api_addInstructDescribe = (data) => {
  const url = baseURL + "setInstructDescribe";
  return service.post(url, data, header);
};

/**
 * 设置指令是否display
 * @param {*} data
 * @returns
 */
export const api_setInstructDisplay = (data) => {
  const url = baseURL + "setInstructDisplay";
  return service.get(url, data, header);
};

export const checkSameInstructName = (data) => {
  const url = baseURL + "zlmcbnyy";
  return service.get(url, data, header);
};

export const getAllSystemInfo = async () => {
  console.log("manage调用getAllSystemInfo");

  const url = baseURL + "faxianxit";
  return service.get(url, { schoolId }, header);
};

export const searchServer = (data) => {
  const url = baseURL + "searchServer2";
  return service.post(url, data, header);
};

export const updateServer = (data) => {
  const url = baseURL + "updateServer2";
  return service.post(url, data, header);
};

export const api_youxianjiaru = (data) => {
  const url = baseURL + "youxianjiaru2";
  return service.post(url, data, header);
};

export const api_changeServerPosition = (data) => {
  const url = baseURL + "changeServerPosition";
  return service.post(url, data, header);
};

// 工作手册
export const api_getAllWorkBook = () => {
  const url = baseURL + "queryAllWorkBook";
  return service.get(url, null, header);
};

export const api_addWorkBook = (data) => {
  const url = baseURL + "addWorkBook";
  return service.post(url, data, header);
};

export const api_updateWorkBook = (data) => {
  const url = baseURL + "updateWorkBook";
  return service.post(url, data, header);
};

export const api_openOrCloseWB = (data) => {
  const url = baseURL + "openOrCloseWB";
  return service.post(url, data, header);
};

export const api_deleteWorkBookById = (data) => {
  const url = baseURL + "deleteWorkBookById";
  return service.post(url, data, header);
};

// 工作手册
export const api_getWorkBookByVersion = (data) => {
  const url = baseURL + "queryWorkBookByVersion";
  return service.get(url, data, header);
};

export const api_listaaa = (data) => {
  const url = baseURL + "listaaa02";
  return service.get(url, data, header);
};

export const api_highOrLow = (data) => {
  const url = baseURL + "highOrLow";
  return service.get(url, data, header);
};

// 再学习页面
export const api_deleteRelearn = (data) => {
  const url = baseURL + "deleteBuriedPoint";
  // const url = baseURL + "sccny";
  return service.post(url, data, header);
};

export const api_remarkRelearn = (data) => {
  const url = baseURL + "remarkBuriedPoint";
  return service.get(url, data, header);
};

export const api_relearnExport = (data) => {
  const url = baseURL + "export";
  let config = {
    responseType: "blob",
    isResponeAll: true,
    params: data,
    headers: header,
  };
  return service.get2(url, config);
};

export const api_instructExport = (data) => {
  const url = baseURL + "exportInstruct";
  let config = {
    responseType: "blob",
    isResponeAll: true,
    params: data,
    headers: header,
  };
  return service.get2(url, config);
};

/**
 * 打开指令核对
 * @returns
 */
export const api_verifyDesktopModule = () => {
  const url = baseURL + "verifyDesktopModule";
  let data = {
    schoolId,
    version,
  };
  return service.get(url, data, header);
};

// ===== 模型数据管理 =====
/**
 * 查询所有模型数据
 *
 */
export const api_queryInstructBert = (data) => {
  const url = baseURL + "queryInstructBert";
  return service.get(url, data, header);
};

/**
 * 查询所有Domain
 *
 */
export const api_queryAllInstructBertDomain = () => {
  const url = baseURL + "queryAllInstructBertDomain";
  return service.get(url, null, header);
};

/**
 * 查询所有Intent
 *
 */
export const api_queryAllInstructBertIntent = () => {
  const url = baseURL + "queryAllInstructBertIntent";
  return service.get(url, null, header);
};

/**
 * 查询所有SlotItem
 *
 */
export const api_queryAllInstructBertSlotItem = () => {
  const url = baseURL + "queryAllInstructBertSlotItem";
  return service.get(url, null, header);
};

/**
 * 更新指令
 *
 */
export const api_updateInstructBert = (data) => {
  const url = baseURL + "updateInstructBert";
  return service.post(url, data, header);
};

/**
 * 更新bert指令的顺序
 *
 */
export const api_updateInstructBertSortIdx = (data) => {
  const url = baseURL + "updateInstructBertSortIdx";
  return service.post(url, data, header);
};

// ===== 校园数据管理 =====
export const api_queryAllSchoolItemBySchoolId = (data) => {
  data.schoolId = schoolId;
  data.version = version;

  const url = baseURL + "queryAllSchoolItemBySchoolId";
  return service.get(url, data, header);
};
